home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / SynthProgressWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  7.2 KB  |  223 lines  |  [TEXT/KAHL]

  1. /* SynthProgressWindow.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "SynthProgressWindow.h"
  31. #include "Memory.h"
  32. #include "Screen.h"
  33. #include "Numbers.h"
  34. #include "DataMunging.h"
  35. #include "EventLoop.h"
  36.  
  37.  
  38. #define WINDOWWIDTH (300)
  39. #define WINDOWHEIGHT (3 + 3 + 4 * GetFontHeight(GetScreenFont(),9))
  40.  
  41.  
  42. struct SynthWinRec
  43.     {
  44.         WinType*                        ScreenID;
  45.         double                            LastTimerValue;
  46.         OrdType                            FontHeight;
  47.         FontType                        ScreenFont;
  48.         long                                CallCountdown;
  49.         long                                CallCountReset;
  50.         MyBoolean                        ShowClippedSamples;
  51.     };
  52.  
  53.  
  54. static void                    WindowUpdateRoutine(SynthWinRec* Window)
  55.     {
  56.         CheckPtrExistence(Window);
  57.     }
  58.  
  59.  
  60. /* create a new synth window record */
  61. SynthWinRec*                NewSynthWindow(long MinCallCount, MyBoolean ShowClippedSamples)
  62.     {
  63.         SynthWinRec*            Window;
  64.  
  65.         Window = (SynthWinRec*)AllocPtrCanFail(sizeof(SynthWinRec),"SynthWinRec");
  66.         if (Window == NIL)
  67.             {
  68.              FailurePoint1:
  69.                 return NIL;
  70.             }
  71.  
  72.         Window->ScreenID = MakeNewWindow(eModelessDialogWindow,eWindowNotClosable,
  73.             eWindowNotZoomable,eWindowNotResizable,DialogLeftEdge(WINDOWWIDTH),
  74.             DialogTopEdge(WINDOWHEIGHT),WINDOWWIDTH,WINDOWHEIGHT,
  75.             (void (*)(void*))&WindowUpdateRoutine,Window);
  76.         if (Window->ScreenID == NIL)
  77.             {
  78.              FailurePoint2:
  79.                 ReleasePtr((char*)Window);
  80.                 goto FailurePoint1;
  81.             }
  82.         SetWindowName(Window->ScreenID,"Progress");
  83.  
  84.         Window->FontHeight = GetFontHeight(GetScreenFont(),9);
  85.         Window->ScreenFont = GetScreenFont();
  86.         Window->LastTimerValue = ReadTimer();
  87.         Window->CallCountdown = 0;
  88.         Window->CallCountReset = MinCallCount;
  89.         Window->ShowClippedSamples = ShowClippedSamples;
  90.  
  91.         PerformDeferredUpdates(); /* update our windows before we start */
  92.         RelinquishCPUCheckCancel(); /* let other programs update too */
  93.  
  94.         SetWatchCursor();
  95.         DrawTextLine(Window->ScreenID,Window->ScreenFont,9,"Preparing...",12,3,3,ePlain);
  96.         DrawTextLine(Window->ScreenID,Window->ScreenFont,9,"Press Escape To Abort",
  97.             21,3,3 + 3 * Window->FontHeight,eBold);
  98.  
  99.         return Window;
  100.     }
  101.  
  102.  
  103. /* dispose of a synth window record */
  104. void                                DisposeSynthWindow(SynthWinRec* Window)
  105.     {
  106.         CheckPtrExistence(Window);
  107.         KillWindow(Window->ScreenID);
  108.         ReleasePtr((char*)Window);
  109.     }
  110.  
  111.  
  112. /* update the information in the synth window */
  113. void                                UpdateSynthWindow(SynthWinRec* Window, long SamplingRate,
  114.                                             long TotalSamples, long TotalClippedSamples, MyBoolean ForceRedraw)
  115.     {
  116.         char*                            StringTemp;
  117.         double                        TimerValue;
  118.  
  119.         CheckPtrExistence(Window);
  120.  
  121.         /* delay so we don't call ReadTimer() all the time */
  122.         Window->CallCountdown -= 1;
  123.         if (!ForceRedraw && (Window->CallCountdown >= 0))
  124.             {
  125.                 return;
  126.             }
  127.         Window->CallCountdown = Window->CallCountReset;
  128.  
  129.         /* make sure we were called at least 1 real seconds ago. */
  130.         TimerValue = ReadTimer();
  131.         if (!ForceRedraw && (ReadTimer() - Window->LastTimerValue < 1))
  132.             {
  133.                 return;
  134.             }
  135.         Window->LastTimerValue = TimerValue;
  136.  
  137.         /* we can do this since none of the data is in an inconsistent state (or even */
  138.         /* altered) during playback. */
  139.         PerformDeferredUpdates();
  140.  
  141.         StringTemp = StringToBlockCopy("Elapsed Song Time (Seconds):  ");
  142.         if (StringTemp != NIL)
  143.             {
  144.                 char*                            TimeStr;
  145.  
  146.                 TimeStr = LongDoubleToString((long double)TotalSamples / SamplingRate,5,.01,1e8);
  147.                 if (TimeStr != NIL)
  148.                     {
  149.                         char*                            Combined;
  150.  
  151.                         Combined = ConcatBlockCopy(StringTemp,TimeStr);
  152.                         if (Combined != NIL)
  153.                             {
  154.                                 DrawTextLine(Window->ScreenID,Window->ScreenFont,9,Combined,
  155.                                     PtrSize(Combined),3,3,ePlain);
  156.                                 DrawBoxErase(Window->ScreenID,3 + LengthOfText(Window->ScreenFont,9,
  157.                                     Combined,PtrSize(Combined),ePlain),3,WINDOWWIDTH,Window->FontHeight);
  158.                                 ReleasePtr(Combined);
  159.                             }
  160.                         ReleasePtr(TimeStr);
  161.                     }
  162.                 ReleasePtr(StringTemp);
  163.             }
  164.  
  165.         StringTemp = StringToBlockCopy("Total Generated Frames:  ");
  166.         if (StringTemp != NIL)
  167.             {
  168.                 char*                            SamplesStr;
  169.  
  170.                 SamplesStr = IntegerToString(TotalSamples);
  171.                 if (SamplesStr != NIL)
  172.                     {
  173.                         char*                            Combined;
  174.  
  175.                         Combined = ConcatBlockCopy(StringTemp,SamplesStr);
  176.                         if (Combined != NIL)
  177.                             {
  178.                                 DrawTextLine(Window->ScreenID,Window->ScreenFont,9,Combined,
  179.                                     PtrSize(Combined),3,3 + Window->FontHeight,ePlain);
  180.                                 DrawBoxErase(Window->ScreenID,3 + LengthOfText(Window->ScreenFont,9,
  181.                                     Combined,PtrSize(Combined),ePlain),3 + Window->FontHeight,
  182.                                     WINDOWWIDTH,Window->FontHeight);
  183.                                 ReleasePtr(Combined);
  184.                             }
  185.                         ReleasePtr(SamplesStr);
  186.                     }
  187.                 ReleasePtr(StringTemp);
  188.             }
  189.  
  190.         if (Window->ShowClippedSamples)
  191.             {
  192.                 StringTemp = StringToBlockCopy("Total Clipped Sample Points:  ");
  193.                 if (StringTemp != NIL)
  194.                     {
  195.                         char*                            SamplesStr;
  196.  
  197.                         SamplesStr = IntegerToString(TotalClippedSamples);
  198.                         if (SamplesStr != NIL)
  199.                             {
  200.                                 char*                            Combined;
  201.  
  202.                                 Combined = ConcatBlockCopy(StringTemp,SamplesStr);
  203.                                 if (Combined != NIL)
  204.                                     {
  205.                                         DrawTextLine(Window->ScreenID,Window->ScreenFont,9,Combined,
  206.                                             PtrSize(Combined),3,3 + 2 * Window->FontHeight,ePlain);
  207.                                         DrawBoxErase(Window->ScreenID,3 + LengthOfText(Window->ScreenFont,9,
  208.                                             Combined,PtrSize(Combined),ePlain),3 + 2 * Window->FontHeight,
  209.                                             WINDOWWIDTH,Window->FontHeight);
  210.                                         ReleasePtr(Combined);
  211.                                     }
  212.                                 ReleasePtr(SamplesStr);
  213.                             }
  214.                         ReleasePtr(StringTemp);
  215.                     }
  216.             }
  217.  
  218.         DrawTextLine(Window->ScreenID,Window->ScreenFont,9,"Press Escape To Abort",
  219.             21,3,3 + 3 * Window->FontHeight,eBold);
  220.  
  221.         SetWatchCursor();
  222.     }
  223.